/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * This class represent the entity client that is store in the database
 * The JPA is used to store this entity in a database
 * @author Guillaume, Yann
 */
@NamedQueries({
    @NamedQuery(name = "findUser", query = "SELECT c FROM Client c WHERE c.name LIKE :name"),
    @NamedQuery(name = "findAllUser", query = "SELECT c FROM Client c")})
@Entity
public class Client implements Serializable {
    private static final int ADMIN = 0;
    private static final int COADMIN = 1;
    private static final int USER = 5;
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private String name;
    private String password;
    private int grade;
    private boolean ban;
    
    /**
     * Create a new instance of a client
     */
    public Client(){
        
    }
    
    /**
     * Create a new instance of the client
     * @param name          client name
     * @param password      client password
     */
    public Client( String name, String password){
        this.name = name;
        this.password = password;
        this.grade = USER;
        this.ban = false;
    }
    
    /**
     * Get the ID of the client in the database
     * @return      client id
     */
    public int getId() {
        return id;
    }
    /**
     * To know is the client is ban
     * @return      boolean with the value of the ban
     */
    public boolean isBan() {
        return ban;
    }
    
    /**
     * Enable to ban a user
     * @param ban       True = ban/ False = unbanned
     */
    public void setBan(boolean ban) {
        this.ban = ban;
    }
    /**
     * To know if a user is ban or not
     * @return if return true, the user is ban else the user is not ban
     */
    public boolean getBan(){
        return this.ban;
    }

    /**
     * Get the grade of a client, lower is more powerful
     * @return      the client grade
     */
    public int getGrade() {
        return grade;
    }

    /**
     * Change the grade of the client
     * @param grade     new client grade
     */
    public void setGrade(int grade) {
        this.grade = grade;
    }
    
    /**
     * Get client name
     * @return      client name
     */
    public String getName() {
        return name;
    }

    /**
     * Change client name
     * @param name      new client name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Retrieve client password
     * @return  client password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Change client password
     * @param password      new password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Client)) {
            return false;
        }
        Client other = (Client) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "controller.client[ id=" + id + " ]";
    }
    
}
